Applescript do javascript submit in safari

Hi,


I have a script that is supposed to do a bunch of stuffs on safari like ticking radio boxes and all, saving then submitting.


However, upon clicking the submit button - manually / with script, there'll be a pop up window with options " OK or Cancel ".


tell application "Safari"

-- this triggers the pop up window

do JavaScript ("document.getElementById('submitButton').click()") in document 1


-- trying to click the ok button using whatever knowledge I know

tell application "System Events" to key code 36

tell application "System Events" to tell process "Safari"

if exists (button "OK" of window 1) then

click (button "OK" of window 1)

end if

end tell


I think the main problem is the script "waits" at the do Javascript line for a response of an OK or cancel before it continues running the rest of the script like hitting enter or clicking the OK/ cancel. It is not a new window, and the pop up window cannot be dragged/moved.

Is there a way to solve this?

OS X El Capitan (10.11.4), null

Posted on Jun 28, 2016 1:08 AM

Reply
3 replies

Jun 28, 2016 8:02 PM in response to Camelot

Well.. the first submit button that the script clicks using "do JavaScript ("document.getElementById('submitButton').click()") indocument 1" has an onclick javascript function attached to it.


function submitforsettlement() {

var submitOK = confirm("By submitting this sales voucher for settlement, you confirm that the customer has received their goods and \nyou have kept a signed copy of the sales voucher.");

if (submitOK) {

// does the success path of submitting

}
}


How do I toggle that submitOK var to true in "do JavaScript ("document.getElementById('submitButton').click()") indocument 1"?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript do javascript submit in safari

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.